//
//  XIFont.h
//  VectorRacer
//
//  Created by Jonathan Nobels on 10/12/09.
//  Copyright 2009 Barn*Star Studios. All rights reserved.
//

#import <Foundation/Foundation.h>
//#import "OpenGLCommon.h"
#import "Texture2D.h"
#import "XIEngine.h"

#define kVRFontMaxLength 48

//This is your ASCII offset... Start your maps at the "space" and include everything
//up to ASCII 128...  This class will kak if you leave out any of the characters...
#define kFMCharStart	 32 


/*
If you don't have "OpenGLCommon.h" - it simply defines a few data structures... 
The important ones are these two:
*/

typedef struct {float x; float y; float z;}Vector3D;
typedef struct {float x; float y;}Vector2D;



//The glyph structure used to store glyph data
typedef struct {
	int			character;		//ASCII value
	int			a;				//Lead in pixels	
	int			c;				//Lead out pixels
	int			width;			//Character width in pixels
	int			height;			//Character height in pixels
	Vector2D	topLeft;		//Normalized UV top left co-ordinate
	Vector2D    bottomRight;	//Normalized UV bottom right co-ordinate
	Vector2D	uvs[6];			//UVs used to draw our triangles (calculated)
}vrFontGlyph;



@interface XIFont : NSObject {
	vrFontGlyph		*_glyphs;
	int				_glyphCount;
	Texture2D		*_fontTexture;
	
	Vector2D		_uvs[kVRFontMaxLength*6];
	Vector3D		_verts[kVRFontMaxLength*6];
}


//Initialize with a font def and a texture file.  Do not use the full path -
//this will automatically find the files in your app bundle.
-(id)initWithFontDef:(NSString *)fName withTexture:(NSString *)tName;

//Called automatically by initWithFontDef...
-(void)loadFontTextureFromFile:(NSString *)fName;
-(void)parseFontDef:(NSString *)fName;

//Debug method to check if the parser is working properly
-(void)printGlyphData:(vrFontGlyph*)g;

//Use to render your strings...
-(void)renderString:(NSString *)string inRect:(CGRect)r;
-(void)renderString:(NSString *)string inRect:(CGRect)r color:(XIPaint)color;
-(void)renderString:(NSString *)string inRect:(CGRect)r centered:(bool)centered color:(XIPaint)color;


-(void)generateUVData:(vrFontGlyph*)g;

@end
